home *** CD-ROM | disk | FTP | other *** search
/ 3D Game Programming All in One / 3D Game Programming All in One Disc.iso / 3D2E / RESOURCES / KOOB / common / client / recordings.cs < prev    next >
Text File  |  2005-11-23  |  3KB  |  112 lines

  1. //-----------------------------------------------------------------------------
  2. // Torque Game Engine 
  3. // Copyright (C) GarageGames.com, Inc.
  4. //-----------------------------------------------------------------------------
  5.  
  6. //-----------------------------------------------------------------------------
  7. // RecordingsGui is the main TSControl through which the a demo game recording
  8. // is viewed. 
  9. //-----------------------------------------------------------------------------
  10.  
  11. function recordingsDlg::onWake()
  12. {
  13.    RecordingsDlgList.clear();
  14.    %i = 0;
  15.    %filespec = $currentMod @ "/recordings/*.rec";
  16.    echo(%filespec);
  17.    for(%file = findFirstFile(%filespec); %file !$= ""; %file = findNextFile(%filespec)) 
  18.    { 
  19.       %fileName = fileBase(%file);
  20.       if (strStr(%file, "/CVS/") == -1) 
  21.       {
  22.          RecordingsDlgList.addRow(%i++, %fileName);
  23.       }
  24.    }
  25.    RecordingsDlgList.sort(0);
  26.    RecordingsDlgList.setSelectedRow(0);
  27.    RecordingsDlgList.scrollVisible(0);
  28. }
  29.  
  30. function StartSelectedDemo()
  31. {
  32.    // first unit is filename
  33.    %sel = RecordingsDlgList.getSelectedId();
  34.    %rowText = RecordingsDlgList.getRowTextById(%sel);
  35.  
  36.    %file = $currentMod @ "/recordings/" @ getField(%rowText, 0) @ ".rec";
  37.  
  38.    new GameConnection(ServerConnection);
  39.    RootGroup.add(ServerConnection);
  40.  
  41.    if(ServerConnection.playDemo(%file))
  42.    {
  43.       Canvas.setContent(PlayGui);
  44.       Canvas.popDialog(RecordingsDlg);
  45.       ServerConnection.prepDemoPlayback();
  46.    }
  47.    else 
  48.    {
  49.       MessageBoxOK("Playback Failed", "Demo playback failed for file '" @ %file @ "'.");
  50.       if (isObject(ServerConnection)) {
  51.          ServerConnection.delete();
  52.       }
  53.    }
  54. }
  55.  
  56. function startDemoRecord()
  57. {
  58.    // make sure that current recording stream is stopped
  59.    ServerConnection.stopRecording();
  60.    
  61.    // make sure we aren't playing a demo
  62.    if(ServerConnection.isDemoPlaying())
  63.       return;
  64.    
  65.    for(%i = 0; %i < 1000; %i++)
  66.    {
  67.       %num = %i;
  68.       if(%num < 10)
  69.          %num = "0" @ %num;
  70.       if(%num < 100)
  71.          %num = "0" @ %num;
  72.  
  73.       %file = $currentMod @ "/recordings/demo" @ %num @ ".rec";
  74.       if(!isfile(%file))
  75.          break;
  76.    }
  77.    if(%i == 1000)
  78.       return;
  79.  
  80.    $DemoFileName = %file;
  81.  
  82.    ChatHud.AddLine( "\c4Recording to file [\c2" @ $DemoFileName @ "\cr].");
  83.  
  84.    ServerConnection.prepDemoRecord();
  85.    ServerConnection.startRecording($DemoFileName);
  86.  
  87.    // make sure start worked
  88.    if(!ServerConnection.isDemoRecording())
  89.    {
  90.       deleteFile($DemoFileName);
  91.       ChatHud.AddLine( "\c3 *** Failed to record to file [\c2" @ $DemoFileName @ "\cr].");
  92.       $DemoFileName = "";
  93.    }
  94. }
  95.  
  96. function stopDemoRecord()
  97. {
  98.    // make sure we are recording
  99.    if(ServerConnection.isDemoRecording())
  100.    {
  101.       ChatHud.AddLine( "\c4Recording file [\c2" @ $DemoFileName @ "\cr] finished.");
  102.       ServerConnection.stopRecording();
  103.    }
  104. }
  105.  
  106. function demoPlaybackComplete()
  107. {
  108.    disconnect();
  109.    Canvas.setContent("MainMenuGui");
  110.    Canvas.pushDialog(RecordingsDlg);
  111. }
  112.